package me.zhengjie.modules.file.service.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: Firework
 * @Description:
 * @Date Created in 11:232021/4/7
 * @Modidied By:
 */
@Data
public class FileOwnModel {
    private Integer id;

    /** 可查看用户 */
    private Integer audienceId;

    /** 创建时间 */
    private Timestamp createTime;
    public FileOwnModel(){

    }

    /** 是否公开 */
    private Integer isPublic;
    /** 文件名 */
    private String fileName;
    /** 文件地址 */
    private String filePath;
    private String type;
    private String size;

    public FileOwnModel(Integer id, Integer audienceId, Object createTime,
                        Integer isPublic, String fileName, String filePath, String type, String size) {
        this.id = id;
        this.audienceId = audienceId;
        this.createTime = stringToTimestamp(createTime.toString());
        this.isPublic = isPublic;
        this.fileName = fileName;
        this.filePath = filePath;
        this.type=type;
        this.size=size;
    }
    public static Timestamp stringToTimestamp(String dateStr){

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Calendar cal = Calendar.getInstance();
        try {
            Date date = sdf.parse(dateStr);
            date.getTime();
            cal.setTime(date);
            return new Timestamp(cal.getTimeInMillis());
        } catch (ParseException e) {
            e.printStackTrace();
        }

        cal.setTime(new Date());
        return new Timestamp(cal.getTimeInMillis());
    }
}
